package com.ffz.springcloud.controller;

import com.ffz.springcloud.bean.CommonResult;
import com.ffz.springcloud.bean.Payment;
import com.ffz.springcloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName : controller.java
 * @Description : //
 * @Author fengfazheng
 * @Date 2020-12-07 19:32
 * @Version : 1.0
 */
@RestController
@Slf4j
public class PaymentController {
    @Autowired
    private PaymentService paymentService;
    @Value("${server.port}")
    private String serverPort;
    @PostMapping("/payment/create")
    public CommonResult create(@RequestBody Payment payment){
    boolean save = paymentService.save(payment);
    if(save){
        return new CommonResult(200,"插入成功！"+serverPort,1);
    }else{
        return new CommonResult(444,"插入失败！",null);
    }
}

    @GetMapping("/payment/get/{id}")
    public CommonResult getPaymentById(@PathVariable("id") Long id){
        Payment payment= paymentService.getById(id);
        log.info("hahh");
        if(payment!=null){
            return new CommonResult(200,"查询成功！"+serverPort,payment);
        }else{
            return new CommonResult(444,"查询失败！",null);
        }
    }
}
